﻿using MJTop.Data;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ESMAM.DAL.DAO
{
    public class DAL
    {

        private static DB _db = null;
        public static DB DbTop
        {
            get
            {
                if (_db == null)
                {
                    _db = DBMgr.UseDB(DBType.MySql);
                }
                return _db;
            }
        }

        /// <summary>
        /// 生成新的树状编码
        /// </summary>
        ///<param name="mark">字母标记</param>
        /// <param name="level">级别</param>
        /// <param name="tableName">表面</param>
        /// <returns></returns>
        public string NextTreeCode(string mark, string level, string tableName)
        {
            string sel_sql = "Select  (Max(Cast(Replace(id,'" + mark + "','') As SIGNED))+1) From " + tableName + " Where level=" + level;
            string val = DbTop.Scalar<string>(sel_sql, string.Empty);
            val = val ?? "1";
            val = mark + val.PadLeft(int.Parse(level) + 2, '0');
            return val;
        }
    }
}
